查看原文
其他

ggplotify简史

Y叔叔 YuLabSMU 2022-09-20

在《ggsave支持base plot》一文中提到了ggplotify包,当你可以把图变成ggplot对象之后,对于熟悉ggplot2的用户来说,一切就变得容易搞起来,比如你可以《base X ggplot2,也可以读图变ggplot然后随意制作meme:《制作meme的通用方式,来了解一下》,你也可以在《UpSet图中嵌入Venn》。这个包的背后,是一段历时3年不为人知的故事。

embed base to grid plot (2015, ChIPseeker)

I figured out a way to embed base plot (vennpie) to grid plot (upset) when developing upsetplot function in ChIPseeker package for visualizing overlap of ChIPseq data in 2015, http://guangchuangyu.github.io/2015/07/upsetplot-in-chipseeker/, 《CS6: ChIPseeker的可视化方法》.

embed ggplot (2015, ggtree and ggimage)

I developed a subview function in ggtree package in 2015, for embeding subplots, 

https://github.com/GuangchuangYu/ggtree/commit/2ab2876d5e92454869c3307ea6f3c8e2656630ef.

This function was re-implemented as geom_subview and packed in the ggimage package.

embed plots (base, lattic, ggplot or image) to ggplot (2017, ggimage and hexSticker)

In the early of 2017, I started to develop R script to produce ggtree sticker. @lgatto first came out with an idea of makeing an R package for producing hex sticker by packing my script into a function, https://github.com/Bioconductor/BiocStickers/issues/12. I have several ideas to improve the package, including producing print-ready figure, employing modular design and supporting grammar of graphics, as well as supporting subplot generated by base and lattice. I started to develop the hexSticker package, https://github.com/GuangchuangYu/hexSticker/issues/2, with base plot, lattice, ggplot2 and image file supported as subplot, which was actually implemented in ggimage (toGrob function, image file are supported by geom_image).

convert base to grob (2018, base2grob)

I wrote a blog post, 《扪心自问,meme几何?》, to ask questions based on the meme package to help users understand ggplot2.

After I wrote the sentence:

if you know how ggsave works, you can even extend it to support base plot

I started to extend ggsave to support base plot by using formula or expression, e.g. ggsave(~base_plot).

After that, I asked myself, why not extending cowplot to support base plot with the fact that I already have source code to convert base plot to grob object (ggimage:::toGrob). Then I developed the base2grob package and submit it to CRAN.

convert (almost all) plots to ggplot (2018, ggplotify)

I wrote a blog post, 《ggplot2版本的维恩图》, to introduce ggvenn function (in yyplot package, only available on GitHub), and started to play with the UpSetR package. I believe upset plot contains too much empty space and can embed a venn plot as I did in 2015 with vennpie. I created a PR, https://github.com/hms-dbmi/UpSetR/pull/112, to make it possible to capture upset output and be able to be converted to grob object. I thought it would be more easy if I further convert the object to ggplot then I can directly use ggimage::geom_subview() to embed ggvenn inside upset plot. With this idea, I started to implement as.ggplot function.

Then, I suddenly realized that I should packed as.ggplot, ggimage:::toGrob and base2grob into a single package. That's why we have ggplotify, which contains as.grob to convert plots to grob and as.ggplot to convert plots to ggplot objects.

显摆一下,新鲜出炉的新周边,不容易啊,美帝寄过来,把我电话给写错了,直接导致包裹给寄丢了,我联系了之后,再补寄,还是写错我电话,还好第二次寄的是UPS小包裹,我联系了UPS,才得以拿到!这是用ggtree纯代码画的biobabble公众号logo,GC两个字母,DNA最强基佬对!


往期精彩

您可能也对以下帖子感兴趣

文章有问题?点此查看未经处理的缓存